#pragma once
#include <vector>

// Type flags
#define NF_INLET    0x0001
#define NF_OUTLET   0x0002
#define NF_INOUT    (NF_INLET | NF_OUTLET)
#define NF_SPAWN    0x0004
#define NF_SELECTED 0x0100

#define BITCMP(i, flg) ((i & flg) == flg)

class CAgent;
typedef std::vector<CAgent*> CAgentPtrVec;

/******************************************************************************
 * CNode Definition
 *****************************************************************************/
class CNode
{
public:
    CNode();
    ~CNode();
    void Paint(CPaintDC& dc, bool drawNode, bool drawConnections, bool drawFares);
    void DrawNode(CPaintDC& dc);
    void DrawFares(CPaintDC& dc, bool nodeDrawn);
    void DrawLineTo(CNode* n, CPaintDC& dc);
    int GetDistance(CNode* n);

    // Operator overloads
    bool operator==(const CNode& other);
    CNode& operator=(const CNode& other);

    int m_id;
    CPoint m_pt;

    int m_numFares;
    int m_trafN;
    int m_trafS;
    int m_trafE;
    int m_trafW;

    CNode* m_north;
    CNode* m_south;
    CNode* m_east;
    CNode* m_west;
    unsigned short m_type;

    int m_dfs;
    CNode* m_prev;
    CAgentPtrVec m_agents;
};

// STL Typedefs
typedef std::vector<CNode*>             CNodePtrVec;
typedef CNodePtrVec::iterator           CNodePtrVecIter;
typedef CNodePtrVec::const_iterator     CNodePtrVecCIter;
typedef std::vector<CNodePtrVec>        CNodePtrVec2d;
typedef CNodePtrVec2d::iterator         CNodePtrVec2dIter;
typedef CNodePtrVec2d::const_iterator   CNodePtrVec2dCIter;

// Forward declaration
class CPath;
typedef std::vector<CPath*> CPathPtrVec;

/******************************************************************************
 * CPath Definition
 *****************************************************************************/
class CPath
{
public:
    CPath(CNode* src, CNode* dest);
    ~CPath();
    bool operator==(const CPath& other);
    static CPath* FindPath(int idSrc, int idDest, CPathPtrVec& vecPaths);
    CNodePtrVec* GetPath();
    
    CNode* GetSource();
    CNode* GetDestination();
    void Add(CNode* node);
    CNodePtrVecIter GetIterator();

protected:
    CNodePtrVec m_path;   
    CNode* m_src;
    CNode* m_dest;
};
typedef std::vector<CPath*>         CPathPtrVec;
typedef CPathPtrVec::iterator       CPathPtrVecIter;
typedef CPathPtrVec::const_iterator CPathPtrVecCIter;

/******************************************************************************
 * CNodeMap Definition
 *****************************************************************************/
class CNodeMap
{
public:
    CNodeMap();
    ~CNodeMap();

    CString LoadMapFile(const CString& strMapFile);
    void Paint(const CRect& rect, CPaintDC& dc);
    
    CNodePtrVec m_vecNodes;	
    CNodePtrVec m_vecInlets;
    CNodePtrVec m_vecOutlets;
    CPathPtrVec m_vecPaths;

    bool m_drawSpawns;
    bool m_drawNodes;
    bool m_drawConnections;
    bool m_drawFares;
};

